<template>
  <section @click="click" class="my_button" :class="{ hover: active }">
    <slot></slot>
  </section>
</template>

<script setup lang="ts">
import { ref } from 'vue';
const active = ref(false);

const X = ref('0px');
const Y = ref('0px');
// let X = '0px';
// let Y = '0px';
function click(e: MouseEvent) {
  if (active.value) {
    return;
  }
  const target = e.target as HTMLAreaElement;
  X.value = `${e.clientX - target.offsetLeft}px`;
  Y.value = `${e.clientY - target.offsetTop}px`;
  active.value = true;
  setTimeout(() => {
    active.value = false;
  }, 1000);
}
</script>

<style lang="less" scoped>
.my_button {
  position: relative;
  cursor: pointer;
  border: none;
  background-image: linear-gradient(90deg, #755bea, #ff72c0);
  padding: 12px 36px;
  border-radius: 40px;
  font-size: 18px;
  color: #fff;
  letter-spacing: 0.1rem;
  user-select: none;
  overflow: hidden;
  display: inline-block;
}
.hover::after {
  content: '';
  position: absolute;
  animation: spread 0.8s linear infinite;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  top: v-bind(Y);
  left: v-bind(X);
  background-color: #fff;
  z-index: 10;
}
@keyframes spread {
  from {
    width: 0px;
    height: 0px;
    opacity: 0.5;
  }
  to {
    width: 300px;
    height: 300px;
    opacity: 0;
  }
}
</style>
